// pages/reg/reg.js
var app = getApp()
var admin_id = app.globalData.admin_id;

var share = app.globalData.share;
Page({

	/**
	 * 页面的初始数据
	 */
	data: {

	},
	onLoad: function (options) {
    var that = this;
		this.setData({
			vipInfo: app.globalData.vipinfo
		})

    wx.request({
      url: app.globalData.host + 'index.php/api/goods/goodsInfo?admin_id=' + app.globalData.admin_id + '&type=' + 67211 + '&code=3',
      success: function (e) {
        that.setData({
          items: e.data.result[0]
        })
        if (e.data.result[0].f_2){
          that.setData({
            addmoney: e.data.result[0].f_2
          })
        }else{
          that.setData({
            addmoney: 0
          })
        }
        
      }
    })
	},
	submit: function (e) {
		// console.log(e);
		var that = this;


		if (e.detail.value.tell.length == 0 || e.detail.value.tell == 0) {
			return false;
		}
		else {
			
      let temp = Math.floor(e.detail.value.tell / 100)
      console.log('充值金额：', parseFloat(temp * that.data.addmoney) + parseFloat(e.detail.value.tell)) 

			app.payFor(that.data.vipInfo.nickname, that.data.vipInfo.mobile, e.detail.value.tell, "【充值】" + that.data.vipInfo.nickname, function () {
				wx.request({
					url: 'https://xcxu.we-fs.com/index.php/api/goods/order1',
					method: 'post',
					data: {
						'name': that.data.vipInfo.nickname,
						'sj': that.data.vipInfo.mobile,
						'goods_name': "【充值】" + that.data.vipInfo.nickname,
						'price': e.detail.value.tell,
						// 'liuyan': e.currentTarget.dataset.liuyan,
						// 'dz': r.provinceName + r.cityName + r.countyName + r.detailInfo,
						'admin_id': admin_id,
            'goods_id': that.data.items.goods_id,
						'openid': app.globalData.openid
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: function (res) {
						console.log(res.data)

						setTimeout(function () {
							that.setData({
								loadingHidden: true
							})
						}, 1500)
					}
				})

        app.opInt(parseFloat(temp * that.data.addmoney) + parseFloat(e.detail.value.tell), 'user_money', 1, function () {
					// app.showPop('充值成功', true)
					setTimeout(function () {
						wx.switchTab({
							url: '../../pages/link/link',
						})
					}, 1500)
				})

			})
		}

	},
	toindex: function () {
		wx.switchTab({
			url: '../../pages/index/index',
		})
	}
})